package com.ycdx.zwzc.action;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;
import com.ycdx.zwzc.impl.ServiceTypeImpl;
import com.ycdx.zwzc.pojo.ServiceType;

public class ServiceTypeAction extends ActionSupport implements Preparable{
	
	private List<ServiceType> allServiceTypes;
	private static final long serialVersionUID = -512728776868877795L;
	private ServiceType st;
	private String id;
	
	
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public ServiceType getSt() {
		return st;
	}
	public void setSt(ServiceType st) {
		this.st = st;
	}
	public List<ServiceType> getAllServiceTypes() {
		return allServiceTypes;
	}
	public void setAllServiceTypes(List<ServiceType> allServiceTypes) {
		this.allServiceTypes = allServiceTypes;
	}
	public String show(){
		return "success";
	}
	public String add(){
		return "success";
	}
	
	/**
	 * 添加产品类别
	 * @return
	 */
	public String addNew(){
		int flag = ServiceTypeImpl.addServiceType(st);
		//System.out.println(request.getEditor());
		if(flag==1){
			//添加成功
			addActionMessage("产品类别添加成功！");
			
		}else{
			//添加不成功
			addActionMessage("产品类别添加不成功，请重试！");
			
		}
		return "list";
	}
	
	public String edit(){
		st = ServiceTypeImpl.getServiceTypeById(id);
		return "success";
	}
	
	/**
	 * 产品类别修改
	 * @return
	 */
	public String update(){
		int flag = ServiceTypeImpl.update(st);
		//System.out.println(request.getEditor());
		if(flag==1){
			//添加成功
			addActionMessage("产品类别修改成功！");
			
		}else{
			//添加不成功
			addActionMessage("产品类别修改不成功，请重试！");
			
		}
		return "list";
	}
	
	public String delete(){
		//System.out.println(id);
		int flag = ServiceTypeImpl.deleteServiceType(id);
		//System.out.println(flag);
		if(flag==1){
			//删除成功
			addActionMessage("产品类别删除成功！");
			
		}else{
			//添加不成功
			addActionMessage("产品类别删除不成功，请重试！");
			
		}
		return "list";
	}
	/**
	 * 初始化产品类型
	 */
	public void prepare() throws Exception {
		// TODO Auto-generated method stub
		allServiceTypes = ServiceTypeImpl.queryAllServiceType();
	}
	
	
}
